#include <iostream>
using namespace std;

// 确实没啥好注释的了

int add(int a, int b)
{
	return a + b;
}

int sub(int a, int b)
{
	return a - b;
}

int mul(int a, int b)
{
	return a * b;
}

int divi(int a, int b)
{
	if (b == 0)
		return 0x7fffffff;
	else
		return a / b;
}

int (*menu[])(int a, int b) = {add, sub, mul, divi};

int main()
{
	cout << endl
		 << "学号：3170608043，姓名：石英钰" << endl
		 << endl
		 << "p120【例3-10】菜单程序" << endl
		 << endl;
	int num1, num2, choice;
	cout << "Select operator:" << endl;
	cout << "  1:add" << endl;
	cout << "  2:sub" << endl;
	cout << "  3:multiply" << endl;
	cout << "  4:divide" << endl;
	cin >> choice;
	cout << "Input number(a,b):";
	cin >> num1 >> num2;
	cout << "Result:" << menu[choice - 1](num1, num2) << endl;
	return 0;
}
